package ar.com.sebasoft.rembrandt.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.widget.Toast;

/**
 * @author SebaSOFT
 *
 */
public class SystemHelper {

	public static String APP_TAG = "ar.com.sebasoft.rembrandt";
	private static Context currentContext = null;
	private static SharedPreferences currentPreferences = null;

	public static void msjShortToast(int msgId) {
		msjToast(msgId, Toast.LENGTH_SHORT);
	}

	public static void msjLongToast(int msgId) {
		msjToast(msgId, Toast.LENGTH_LONG);
	}

	public static void msjLongToast(int msgId, Object... params) {
		String msgString = currentContext.getString(msgId, params);
		msjToast(msgString, Toast.LENGTH_LONG);
	}

	public static void msjShortToast(int msgId, Object... params) {
		String msgString = currentContext.getString(msgId, params);
		msjToast(msgString, Toast.LENGTH_LONG);
	}

	public static String getLocalizedString(int msgId) {
		return currentContext.getString(msgId);
	}
	public static String getLocalizedString(int msgId, Object... replace) {
		return currentContext.getString(msgId,replace);
	}

	public static String[] getLocalizedArray(int resId) {
		return currentContext.getResources().getStringArray(resId);
	}

	public static String getPrefString(String key) {
		return getPrefString(key, null);
	}

	public static String getPrefString(String key, String defaultVal) {
		return currentPreferences.getString(key, defaultVal);
	}

	public static boolean getPrefBoolean(String key) {
		return getPrefBoolean(key, false);
	}

	public static boolean getPrefBoolean(String key, boolean defaultVal) {
		return currentPreferences.getBoolean(key, defaultVal);
	}

	public static float getPrefFloat(String key) {
		return getPrefFloat(key, -1f);
	}

	public static float getPrefFloat(String key, float defaultVal) {
		return currentPreferences.getFloat(key, defaultVal);
	}

	public static int getPrefInt(String key) {
		return getPrefInt(key, -1);
	}

	public static int getPrefInt(String key, int defaultVal) {
		return currentPreferences.getInt(key, defaultVal);
	}

	public static long getPrefLong(String key) {
		return getPrefLong(key, -1);
	}

	public static long getPrefLong(String key, long defaultVal) {
		return currentPreferences.getLong(key, defaultVal);
	}

	private static void msjToast(int msgId, int duration) {
		Toast.makeText(currentContext, msgId, duration).show();
	}

	private static void msjToast(String msgString, int duration) {
		Toast.makeText(currentContext, msgString, duration).show();
	}

	/**
	 * @param currentContext
	 *            the currentContext to set
	 */
	public static void setCurrentContext(Context currentContext) {
		SystemHelper.currentContext = currentContext;
		currentPreferences = PreferenceManager.getDefaultSharedPreferences(currentContext);
	}

	public static void msjShortToast(String msgString) {
		msjToast(msgString, Toast.LENGTH_SHORT);
	}

	public static void msjLongToast(String msgString) {
		msjToast(msgString, Toast.LENGTH_LONG);
	}
}
